<?php get_header(); ?>
<!--<a href="<?php //echo xemphim($idphim); ?>">xem phim</a>-->

<?php $options = get_option('nominal'); ?>

<?php 
    $idphim = get_the_ID();
    $idtap = get_query_var('ep');
?>
<?php 
    include("picasa.php"); 
?>

<div class="main-container">
<div id="page">
    <div id="content">
    <?php if ( have_posts() ) while ( have_posts() ) : the_post(); ?>
        <article class="container content article">
            <?php if ($options['mts_breadcrumb'] == '1') { ?>
    			<div class="breadcrumb"><?php the_breadcrumb(); ?></div>
    		<?php } ?>
            <div><h2><?php the_title(); ?></h2></div>
            
            <?php if($idtap != ''): ?>
                    <?php //echo getlinkphim($idphim,$idtap); ?>
                    <?php   
                        $idtap=del_id($idtap);
                        $url = $wpdb->get_row("SELECT episode_url FROM wp_film_episode WHERE episode_film = '".$idphim."' AND episode_id='".$idtap."'");
                        $url = $url->episode_url;
                        if(strpos($url, 'fshare') !== false):
                    ?>
                    <div id="code-js">
                    <script type="text/javascript">
                        
                        $(document).ready(function(){
                            $.ajax({
                                url:"<?php echo get_template_directory_uri().'/fshare/index.php' ?>",
                                type:"post",
                                data: { link: "<?php echo $url; ?>", pass: "<?php echo md5(md5('$$$mot2ba4nam6bay8chin###')); ?>", key: "<?php echo md5($key); ?>"} ,
                                success:function(response){
                                    //$('#video_content').hide().html(response).fadeIn('slow');
                                    if(response != ''){
                                        var obj = jQuery.parseJSON(response);
                                        $('video').attr('src', obj.url);
                                        $('video').find('source').attr('src', obj.url);
                                        $('video').attr('HD', obj.url);
                                        $('video').attr('nonHD', obj.url);
                                        $('#video_content').append(obj.script);
                                    }
                                }
                            });
                        });
                    </script>
                    </div>
                    <div id="video_content" style="width: 100%; height: 480px;">
                        <video controls preload autoplay id="video" class="video-js vjs-default-skin vjs-big-play-centered"
                            width="100%" height="480" poster="<?php echo get_template_directory_uri().'/img/loading2.gif';  //echo get_field( "poster" ); ?>" >
                            <source type="video/mp4" >
                            <p class="vjs-no-js">Vui lòng bật javascript, hay dùng trình duyệt mới Chrome hay Firefox hay EI 10 trở lên</p>
                        </video>
                    </div>
                    <?php else:?>
                        <?php 
                            $result = getPicasaPlus($url); 
                            $pass = md5('mot2ba4nam6bay8');
                        ?>
                    <div id="video_content_picasa">
                        <video controls preload autoplay id="video" class="video-js vjs-default-skin vjs-big-play-centered"
                            poster="<?php //echo get_template_directory_uri().'/img/loading2.gif';  //echo get_field( "poster" ); ?>"
                            HD="<?php if(!empty($result['HD']['url'])) echo get_template_directory_uri().'/picasa.php?videoPicasa='.base64_encode($result['HD']['url']).$pass; else echo get_template_directory_uri().'/picasa.php?videoPicasa='.base64_encode($result['SD']['url']).$pass; ?>"
                            nonHD="<?php if(!empty($result['SD']['url'])) echo get_template_directory_uri().'/picasa.php?videoPicasa='.base64_encode($result['SD']['url']).$pass; ?>" 
                            width="100%" height="480" controls>
                                <source type="video/mp4" src="<?php echo get_template_directory_uri().'/picasa.php?videoPicasa='.base64_encode($result['SD']['url']).$pass; ?>" />
                                <p class="vjs-no-js">Vui lòng bật javascript, hay dùng trình duyệt mới Chrome hay Firefox hay EI 10 trở lên</p>
                        </video>
                    </div>
                    
                <?php endif; ?>
                
                <?php echo episode_show($idphim);?>
                <div class="filmDes">
                    <?php the_content(); ?>
                </div>
                <script type="text/javascript">function setActive(){aObj=document.getElementById("servers").getElementsByTagName("a");for(i=0;i<aObj.length;i++)0<=document.location.href.indexOf(aObj[i].href)&&(aObj[i].className="active")}window.onload=setActive;</script>
            <?php else :?>
                <?php if ( has_post_thumbnail() ) { ?>
                    <div id="wrapper-cover-play">
                        <div class="filmLeft"><?php the_post_thumbnail(array(204, 204));  ?></div>
                        <div id="action">
                            <a href="<?php if(xemphim($idphim) == ''): echo 'javascript:showMessage()'; else: echo xemphim($idphim); endif; ?>" class="btn btn-sky text-uppercase btn-lg">Xem phim</a>
                            <?php if (xemphim($idphim) == ''): ?>
                                <script type="text/javascript">
                                    function showMessage(){
                                        alert('Phim này hiện tại không tồn tại, vui lòng comment bên dưới để yêu cầu phim này...Xin cảm ơn đã quan tâm.')    
                                    }
                                </script>
                            <?php endif; ?>
                        </div>        
                    </div>
                    <?php }else{ ?>
                        <div id="wrapper-cover-play">
                            <div class="filmLeft">
                                <img src="http://fsharefilm.com/wp-content/uploads/2014/08/default_cover.jpg" />
                            </div>
                            <div id="action">
                                <!--<a href="#" class="btn btn-hot text-uppercase btn-lg">Download</a>-->
                                <a href="<?php echo xemphim($idphim); ?>" class="btn btn-sky text-uppercase btn-lg">
                                    Xem phim
                                </a>
                            </div>
                        </div>
                        
                    <?php } ?>
                <div class="filmRight">
                    <?php 
                        $namSanXuat = get_post_meta($idphim, 'Nam_San_Xuat', true); 
                        $thoiLuong = get_post_meta($idphim, 'Thoi_gian_Sotap', true);
                        $imdb = get_post_meta($idphim, 'danhGia', true);
                        $daoDien = get_post_meta($idphim, 'Dao_Dien', true);
                        $dienVien = get_post_meta($idphim, 'Dien_vien', true);
                        $quocGia = get_post_meta($idphim, 'quocGia', true);
                        $tags = get_post_meta($idphim, 'danhGia', true);
                    ?>
                    <p>Lượt xem: <?php echo_views(get_the_ID()); ?></p>
                	<p><?php if(get_field('nam_san_xuat')): echo 'Năm phát hành: '.get_field('nam_san_xuat'); else: if($namSanXuat != ''): echo 'Năm phát hành: '.$namSanXuat;endif; endif; ?></p>
                    <p><?php if(get_field('thoi_luong')): echo 'Thời lượng: '.get_field('thoi_luong'); else: if($thoiLuong != ''): echo 'Thời lượng: '.$thoiLuong;endif; endif; ?></p>
                    <p><?php if(get_field('imdb')): echo 'IMDB: '.get_field('imdb'); else: if($imdb != ''): echo 'IMDB: '.$imdb;endif; endif; ?></p>
                    <p><?php if(get_field('dao_dien2')): echo 'Đạo diễn: '.get_field('dao_dien2'); else: if($daoDien != ''): echo 'Đạo diễn: '.$daoDien;endif; endif; ?></p>
                    <p><?php if(get_field('dien_vien2')): echo 'Diễn viên: '.get_field('dien_vien2'); else: if($dienVien != ''): echo 'Diễn viên: '.$dienVien;endif; endif; ?></p>
                    <p><?php if(get_field('quoc_gia2')): echo 'Quốc gia: '.get_field('quoc_gia2'); else: if($quocGia != ''): echo 'Quốc gia: '.$quocGia;endif; endif; ?></p>
                    <p class="none-underline">Thể loại: <?php the_category(', '); ?></p>
                    <p class="none-underline"> 
                        <?php
                            $tags = get_the_tags('', ', ', '');
                            if(!empty($tags)):
                                the_tags('Tags: ', ', ', '');
                            endif;
                        ?> 
                    </p>
                </div>
                <div class="filmDes">
                    <?php $content = get_the_content(); ?>
                    <?php if (strpos($content ,'wptab') !== false): ?>
                        <?php $trailer = get_field('trailer'); ?>
                        <?php if(!empty($trailer)): ?>
                            <h3 class="title_h1_st1"><a title="Traler">Trailer: </a></h3>
                            <?php if(strpos($trailer, 'iframe') !== false):  ?>
                                <?php echo $trailer; ?>
                            <?php else: ?>
                                <iframe width="100%" height="510" src="//www.youtube.com/embed/<?php echo get_field('trailer'); ?>" frameborder="0" allowfullscreen></iframe>
                            <?php endif; ?>
                        <?php endif; ?>
                        <?php the_content(); ?>
                    <?php else: ?>
                    
                        <h3 class="title_h1_st1"><a title="tải các phiên bản">Download &amp; Info: </a></h3>
                        <div class="wordpress-post-tabs tab9999_wrap wordpress-post-tabs-skin-default" "="">
                            <div id="tabs_9999" class="ui-tabs ui-widget ui-widget-content ui-corner-all ui-tabs-horizontal-top ui-helper-clearfix">
                                <ul class="ui-tabs-nav ui-helper-reset ui-helper-clearfix ui-widget-header ui-corner-all" role="tablist">
                                    <li class="ui-state-default ui-corner-top ui-tabs-active ui-state-active" role="tab" tabindex="0" aria-controls="tabs-9999-0" aria-labelledby="ui-id-1" aria-selected="true">
                                        <a href="<?php echo get_permalink(); ?>#tabs-9999-0" class="ui-tabs-anchor" role="presentation" tabindex="-1" id="ui-id-1">Download</a>
                                    </li>
                                </ul>
                                <div class="wpts_cl"></div>
                                <div id="tabs-9999-0" aria-labelledby="ui-id-1" class="ui-tabs-panel ui-widget-content ui-corner-bottom" role="tabpanel" aria-expanded="true" aria-hidden="false">
                                    <?php $linkDownload = get_field('linkDownload'); ?>
                                    <p><a href="<?php if($linkDownload != ''): echo $linkDownload; else: echo 'javascript:void(0)'; endif ?>" target="_blank"><?php echo $linkDownload ?></a></p>
                                </div>
                                <div class="wpts_cl"></div>
                                <div class="wpts_cr"></div>
                            </div>
                        </div>
                        
                        <script type="text/javascript">						
                            jQuery(function(){
                                jQuery( "#tabs_9999" ).posttabs({ 
                                        tabname : "tabs_9999",
                                        fade 	: "1",					
                                        active	: "",					
                                        reload	: "0",					
                                        nav	: "0",					
                                        nexttext: "Next »",					
                                        prevtext: "« Prev",					
                                        enablecookie:"1"				
                                    });
                                })
                        </script>
                        </p>
                        <?php the_content(); ?>
                    <?php endif; ?>
                    <?php echo episode_show($idphim);?>
                </div>
            <?php endif; ?>
            <?php comments_template( '', true ); ?>
        </article>
        <?php if($options['mts_social_buttons'] == '1') { ?>
    		<div class="shareit">
    			<?php if($options['mts_twitter'] == '1') { ?>
    				<!-- Twitter -->
    				<span class="share-item twitterbtn">
    				<a href="https://twitter.com/share" class="twitter-share-button" data-via="<?php echo $options['mts_twitter_username']; ?>">Tweet</a>
    				</span>
    			<?php } ?>
    			<?php if($options['mts_gplus'] == '1') { ?>
    				<!-- GPlus -->
    				<span class="share-item gplusbtn">
    				<g:plusone size="medium"></g:plusone>
    				</span>
    			<?php } ?>
    			<?php if($options['mts_facebook'] == '1') { ?>
    				<!-- Facebook -->
    				<span class="share-item facebookbtn">
    				<div id="fb-root"></div>
    				<div class="fb-like" data-send="false" data-layout="button_count" data-width="150" data-show-faces="false"></div>
    				</span>
    			<?php } ?>
    			<?php if($options['mts_linkedin'] == '1') { ?>
    				<!--Linkedin -->
    				<span class="share-item linkedinbtn">
    				<script type="text/javascript" src="http://platform.linkedin.com/in.js"></script><script type="in/share" data-url="<?php the_permalink(); ?>" data-counter="right"></script>
    				</span>
    			<?php } ?>
    			<?php if($options['mts_stumble'] == '1') { ?>
    				<!-- Stumble -->
    				<span class="share-item stumblebtn">
        				<su:badge layout="1"></su:badge>
        				<script type="text/javascript"> 
            				(function() { 
                				var li = document.createElement('script'); li.type = 'text/javascript'; li.async = true; 
                				li.src = window.location.protocol + '//platform.stumbleupon.com/1/widgets.js'; 
                				var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(li, s); 
            				})(); 
    				    </script>
    				</span>
    			<?php } ?>
    			<?php if($options['mts_pinterest'] == '1') { ?>
    				<!-- Pinterest -->
    				<span class="share-item pinbtn">
    				<a href="http://pinterest.com/pin/create/button/?url=<?php the_permalink(); ?>&media=<?php $thumb = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'large' ); echo $thumb['0']; ?>&description=<?php the_title(); ?>" class="pin-it-button" count-layout="horizontal">Pin It</a>
    				<script type="text/javascript" src="//assets.pinterest.com/js/pinit.js"></script>
    				</span>
    			<?php } ?>
    		</div>
    	<?php } ?><!--Shareit-->
        
    <?php endwhile; ?>
    
    <aside class="sidebar c-4-12">
        <?php get_sidebar(); ?>
    </aside>
    </div>
    
</div>
        	
<?php get_footer(); ?>
